fix: handle empty files in last_n_bytes_of#4687
Open
immanuwell wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for nifty-bassi-e26446 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Signed-off-by: immanuwell <pchpr.00@list.ru>
ca22b6b to
ee7011d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
glintchecks the final newline throughenvoy.base.utils.last_n_bytes_of().On a 0-byte file that helper does a negative seek and blows up with
OSError: [Errno 22] Invalid argument, so the check crashes instead of flagging the file. Empty files are normal repo inputs, so this edge case is pretty legit.Fix
Clamp the seek offset to
0. Empty and short files now return the available tail bytes, nice and boring.Repro
Before this change:
This raised
OSError: [Errno 22] Invalid argument.After this change the same snippet returns
{'empty.txt'}.Checks
pytest -q py/envoy.base.utils/tests/test_utils.py -k 'last_n_bytes_of or ellipsize or is_sha'pytest -q py/envoy.code.check/tests/test_abstract_glint.py -k 'newline_checker_no_newlines or glint_no_newlines or files_with_no_newline'